﻿using System;
using System.Collections.Generic;
using System.Linq;
using Web.Models.CoreData;


namespace Web.ViewModel.CoreData
{
    public class CompanyModel
    {
        /// <summary>
        /// 公司id
        /// </summary>
        public String CompanyId { get; set; }
        /// <summary>
        /// 公司名
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 联系人
        /// </summary>
        public String ContactName { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public String Phone { get; set; }
        /// <summary>
        /// 联系邮箱
        /// </summary>
        public String Email { get; set; }
        /// <summary>
        /// 联系地址
        /// </summary>
        public String Address { get; set; }
        /// <summary>
        /// 网址
        /// </summary>
        public String Website { get; set; }

        /// <summary>
        /// logo图片地址
        /// </summary>
        public String Logo { get; set; }
        /// <summary>
        /// 有效时间
        /// </summary>
        public DateTime? ExpirationDate { get; set; }


        /// <summary>
        /// 终端数量
        /// </summary>
        public int Number;

        /// <summary>
        /// 转换模型
        /// </summary>
        /// <param name="model"></param>
        /// <param name="users"></param>
        /// <returns></returns>
        public CompanyModel ConvertMondel(Company model,List<User> users=null )
        {
            return new CompanyModel()
            {
                ContactName = model.ContactName,
                CompanyId = model.Id,
                Name = model.Name,
                Phone = model.Phone,
                Email = model.Email,
                Address = model.Address,
                ExpirationDate=model.ExpirationDate,
                Logo = model.Logo,
                Website = model.Website,
                Number = users==null?0:users.Where(m=>m.Company==model.Id.ToString()).Count()
            };
        }
        /// <summary>
        /// 模型实体转换
        /// </summary>
        /// <returns></returns>
        public Company ConvertEntity()
        {
            return new Company()
            {
                ContactName = this.ContactName,
                Id = this.CompanyId,
                Name = this.Name,
                Phone = this.Phone,
                Email = this.Email,
                Address = this.Address,
                Logo = this.Logo,
                Website = this.Website,
                ExpirationDate = this.ExpirationDate,
            };
        }


    }
}
